package com.jujia.tmall.base;

import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;


import com.elune.ui.ConnectionToast;

import java.lang.reflect.Field;


public abstract class BaseFragment extends Fragment {

    protected SharedPreferences spBase;
    protected SharedPreferences.Editor editorBase;


    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);
        spBase = getActivity().getSharedPreferences(SealConst.BASE_XML, getActivity().MODE_PRIVATE);
        editorBase = spBase.edit();
    }



    protected void toastFrgMid(String str) {
        ConnectionToast.ToastShowMid(getActivity(), str);
    }

    protected void toastFrgBtm(String str) {
        ConnectionToast.ToastShowBottom(getActivity(), str);
    }


    private AlertDialog mAlertDialog;


    protected void showAlertDialog(Context context, @Nullable String title, @Nullable String message,
                                   @Nullable DialogInterface.OnClickListener onPositiveButtonClickListener,
                                   @NonNull String positiveText,
                                   @Nullable DialogInterface.OnClickListener onNegativeButtonClickListener,
                                   @NonNull String negativeText) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(title);
        builder.setMessage(message);
        builder.setPositiveButton(positiveText, onPositiveButtonClickListener);
        builder.setNegativeButton(negativeText, onNegativeButtonClickListener);
        mAlertDialog = builder.show();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    public String getBaseBraceletXml(String key, String value) {
        return spBase.getString(key, value);
    }

    public void setBraceletXml(String key, String value) {
        editorBase.putString(key, value);
        editorBase.commit();
    }

}
